package main

import (
	"main/douyin"
	"net/http"
	"net/url"
	"strconv"
)

func (w *WebSocketApp) saveUser(user *douyin.User) {
	// 将数据存储到 map 中
	userData := url.Values{
		"user_id":      {strconv.FormatUint(user.Id, 10)},
		"short_id":     {strconv.FormatUint(user.ShortId, 10)},
		"nick_name":    {user.NickName},
		"gender":       {map[int]string{0: "女", 1: "男"}[int(user.Gender)]},
		"avatar_thumb": {user.AvatarThumb.UrlListList[0]},
		"pay_level":    {strconv.FormatInt(user.PayGrade.Level, 10)},
		"follower":     {strconv.FormatUint(user.FollowInfo.FollowerCount, 10)},
		"following":    {strconv.FormatUint(user.FollowInfo.FollowingCount, 10)},
	}
	// 发送 POST 请求
	resp, err := http.PostForm("http://127.0.0.1:8000/api/dy/user", userData)
	if err != nil {
		return
	}
	defer resp.Body.Close()
}

func (w *WebSocketApp) saveMsg(msgID, userID, nickName, content, msgType, roomID string) {
	// 将消息数据存储到 map 中
	msgData := url.Values{
		"msg_id":    {msgID},
		"live_id":   {w.LiveID},
		"user_id":   {userID},
		"nick_name": {nickName},
		"content":   {content},
		"msg_type":  {msgType},
		"room_id":   {roomID},
	}

	// 发送 POST 请求
	resp, err := http.PostForm("http://127.0.0.1:8000/api/dy/msg", msgData)
	if err != nil {
		return
	}
	defer resp.Body.Close()
}

func (w *WebSocketApp) saveGiftRank(msgID, userID, nickName, rankLevel, batchDate, roomID string) {
	// 将礼物排行数据存储到 map 中
	giftRankData := url.Values{
		"msg_id":     {msgID},
		"live_id":    {w.LiveID},
		"user_id":    {userID},
		"nick_name":  {nickName},
		"rank_level": {rankLevel},
		"batch_date": {batchDate},
		"room_id":    {roomID},
	}

	// 发送 POST 请求
	resp, err := http.PostForm("http://127.0.0.1:8000/api/dy/gift_rank", giftRankData)
	if err != nil {
		return
	}
	defer resp.Body.Close()
}
